﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Reflection;
using Fulcrum.DispatcherProxies;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.DispatcherProxies
{
    [TestClass]
    public class DispatcherProxySettingsTests
    {
        public DispatcherProxySettingsTests()
        {
            // nothing
        }

        DispatcherProxySettings settings;

        [TestInitialize]
        public void TestInitialize()
        {
            this.settings = new DispatcherProxySettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestNullTargetAssembly()
        {
            this.settings.Company = "My Company";
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestEmptyTargetAssembly()
        {
            this.settings.TargetAssembly = String.Empty;
            this.settings.Company = "My Company";
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestMissingTargetAssembly()
        {
            this.settings.TargetAssembly = "MyAssembly";
            this.settings.Company = "My Company";
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        public void TestValidSettings()
        {
            //
            // No Exception is pass
            //
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Company = "My Company";
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestMissingNamespace()
        {
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Company = "My Company";
            this.settings.Copyright = "My Copyright";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestEmptyNamespace()
        {
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Company = "My Company";
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestMissingCompany()
        {
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestEmptyCompany()
        {
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Company = "";
            this.settings.Copyright = "My Copyright";
            this.settings.Namespace = "My.Namespace";
            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestMissingCopyright()
        {
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Company = "My Company";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        [TestMethod]
        [ExpectedException(typeof(ApplicationException))]
        public void TestEmptyCopyright()
        {
            this.settings.TargetAssembly = GetThisAssemblyLocation();
            this.settings.Company = "My Company";
            this.settings.Copyright = "";
            this.settings.Namespace = "My.Namespace";

            this.settings.ValidateSettings();
        }

        private static string GetThisAssemblyLocation()
        {
            return Assembly.GetExecutingAssembly().Location;
        }
    }
}
